﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UcAsp.Models;
namespace UcAsp.Controllers
{
    public class VideoController : Controller
    {
        //
        // GET: /Video/
        private UcAspNetEntities entities = new UcAspNetEntities();
        public ActionResult Index(int? page)
        {
            List<Articles> list = new List<Articles>();
            var query = from c in entities.Articless
                        where c.CategorieID==15    &&c.IsRelease==true                  
                        orderby c.ID descending
                        select c;

            int pagesize = 36;
            int pageindex = 0;
            if (page == null)
            {
                page = 1;
            }
            pageindex =Convert.ToInt32(page) - 1;
           
            ViewData["PageIndex"] = pageindex + 1;
            ViewData["PageCount"] = (query.Count() + 35) / 36;

            list = query.Skip(pageindex * pagesize).ToList<Articles>().Take(pagesize).ToList();
            ViewData["recommend"] = entities.Articless.Where(o => o.CategorieID == 13 && o.IsRecommend == true).Take(4).ToList();

            List<Articles> recommend = (from c in entities.Articless
                        where c.CategorieID == 15&&c.IsRecommend==true
                        orderby c.ID descending
                        select c).Take(6).ToList();
            ViewData["recommend"] = recommend;
            return View(list);
        }

    }
}
